package servlet.admin.operator;

import service.OperatorService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet( name = "AdminOperatorsUpdateServlet")
public class AdminOperatorsUpdateServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer operatorID=Integer.parseInt(request.getParameter("operatorID"));
        String name=new String(request.getParameter("name").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        String email=request.getParameter("email");
        String sex= new String(request.getParameter("sex").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//        String photo=request.getParameter("photo");

        OperatorService service=new OperatorService();
        service.update(operatorID,name,email,sex);

        request.getServletContext().getRequestDispatcher("/AdminOperatorsServlet?page=1").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
